/*
 * @Author: szx
 * @Date: 2021-12-24 14:54:42
 * @LastEditTime: 2021-12-24 15:12:04
 * @Description:
 * @FilePath: \leetcode\1-99\98\98.js
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isValidBST = function (root) {
    const dfs = (root, min, max) => {
        if (!root) return true;
        if (root.val <= min || root.val >= max) return false;
        return dfs(root.left, min, root.val) && dfs(root.right, root.val, max);
    };
    return dfs(root, -Infinity, Infinity);
};
var isValidBST = function (root) {
    let pre = -Infinity;
    const dfs = (root) => {
        if (!root) return true;
        if (!dfs(root.left)) return false;
        if (pre >= root.val) return false;
        pre = root.val;
        if (!dfs(root.right)) return false;
        return true;
    };
    return dfs(root);
};
